home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_097 / splines / sprt.c < prev   
C/C++ Source or Header  |  1992-05-06  |  8KB  |  249 lines

  1. /* The routines in this file are copyright (c) 1987 by Helene (Lee) Taran.
  2.  * Permission is granted for use and free distribution as long as the
  3.  * original author's name is included with the code.
  4.  */
  5.  
  6. #include "spline.h"
  7.  
  8. struct IntuitionBase *IntuitionBase; 
  9. struct GfxBase *GfxBase;
  10. struct LayersBase *LayersBase;
  11.  
  12. void *OpenLibrary();
  13. void *OpenWindow();
  14. void *OpenScreen();
  15.  
  16. USHORT pointimage[] =  /* what a control point will look like */
  17.    {0x0000, 0x0000, 0x1c00, 0x3e00, 0x3e00, 0x3e00, 0x1c00 };
  18.  
  19. struct Image control_image = 
  20.  { -4,-4,7,7, 1, &pointimage[0], 0x1, 0x0, NULL};
  21.  
  22. USHORT ColorTable[COLORCOUNT] =   /* Here are the actual colors used      */
  23.     {  
  24.      0x0000,  /* black */
  25.      0x0063,  /* greenish */
  26.      0x0f24,  /* redish  */
  27.      0x000f,  /* blue */
  28.     };
  29.  
  30. struct NewWindow WindowInfo =
  31. { WINDOW_LEFT,              /* Left Edge                               */
  32.   WINDOW_TOP,               /* Top Edge                                */
  33.   WINDOW_WIDTH,             /* Initial Width       (640 =Hires)        */
  34.   WINDOW_HEIGHT,            /* Initial Height      (400 = interlaced)  */
  35.   -1,                       /* DetailPen   (-1 = use screen's)         */
  36.   -1,                       /* BlockPen    (-1 = use screen's)         */
  37.   MOUSEBUTTONS | CLOSEWINDOW , /* <-- IDCMP flags; \/ window flags     */    
  38.   SMART_REFRESH | WINDOWCLOSE| ACTIVATE | REPORTMOUSE,
  39.   NULL,                             /* First Gadget                    */
  40.   NULL,                             /* CheckMark    (used with menus)  */
  41.   (UBYTE *)"Splines",               /* Title                           */
  42.   NULL,                             /* Screen       (null = default)   */
  43.   NULL,                             /* BitMap                          */
  44.   1,                                /* MinWidth   (0 = initial value)  */
  45.   1,                                /* MinHeight  (0 = initial value)  */
  46.   0,                                /* MaxWidth   (0 = initial value)  */
  47.   0,                                /* MaxHeight  (0 = initial value)  */
  48.   CUSTOMSCREEN,                     /* Type                            */
  49. };
  50.  
  51.  
  52. /* The following structure gives all the information that Intuition
  53.  * needs to maintain a customized screen.
  54.  */
  55. struct NewScreen ScreenInfo =
  56.   0,0,                               /* Left Edge, Top Edge   */
  57.   SCREEN_WIDTH,SCREEN_HEIGHT,        /* Screen Width & Height */
  58.   DEPTH,                             /* Number of bit-planes  */
  59.   DETAILPEN,                         /* Detail Pen color register */
  60.   BLOCKPEN,                          /* Background color register */
  61.   VIEWMODE,                          /* ViewMode */
  62.   CUSTOMSCREEN,                      /* Type */
  63.   NULL,                              /* Font : null = use default */
  64.   (UBYTE *)"Splines and PopUp Menus:   by Lee Taran",  /* Screen Title */
  65.   NULL,                              /* Gadgets */
  66.   NULL                               /* CustomBitMap */
  67. };
  68.  
  69. /* Bits to keep track of anything that must eventually be deallocated */
  70. int OpenBits = 0x0000;
  71.  
  72. /* Intuition structures that will be used to setup the background
  73.  * environment. 
  74.  */
  75. struct Window *Window;
  76. struct Screen *Screen;
  77. struct Layer_Info *Layer_Info;
  78.  
  79. struct PopUp_Menu PointMenu, CurveMenu;
  80. struct PopUp_Item PointItem[] = {
  81.   { "Add Point After",  ADD_AFTER,   1,1,0,0,DETAILPEN,NULL},
  82.   { "Add Point Before", ADD_BEFORE,  1,2,0,0,DETAILPEN,NULL},
  83.   { "Move This Point",  MOVE_POINT,  1,2,0,0,DETAILPEN,NULL},
  84.   { "Remove This Point",REMOVE_POINT,1,2,0,0,DETAILPEN,NULL}
  85. };
  86.  
  87. struct PopUp_Item CurveItem[] = {
  88.  { "Open B-Spline Natural Ends", OPENB_NATURAL, 1,2,0,0,DETAILPEN,NULL},
  89.  { "Open B-Spline Triple Knots", OPENB_TRIPLE,  1,2,0,0,DETAILPEN,NULL},
  90.  { "Open Interpolating Spline",  OPEN_INTRPL,   1,2,0,0,DETAILPEN,NULL},
  91.  { "Closed B-Spline",            CLOSEDB,       1,2,0,0,DETAILPEN,NULL},
  92.  { "Closed Interpolating Spline",CLOSED_INTRPL, 1,2,0,0,DETAILPEN,NULL},
  93.  { "Toggle AFrame",              TOGGLEAFRAME,  1,2,0,0,DETAILPEN,NULL},
  94.  { "Redraw",                     REDRAW,        1,2,0,0,DETAILPEN,NULL} ,
  95.  { "  GET ME OUT OF HERE!!",     QUIT,          1,5,0,0,OUTLINEPEN,NULL},
  96. };
  97.  
  98.  
  99. Init_PointMenu ()
  100.   PointItem[0].next = &PointItem[1];
  101.   PointItem[1].next = &PointItem[2];
  102.   PointItem[2].next = &PointItem[3];
  103.   
  104.   PointMenu.depth = 2;
  105.   PointMenu.width = 100;   /* minimum width */
  106.   PointMenu.deactivate = SELECTUP;
  107.   PointMenu.outline_color = OUTLINEPEN;
  108.   PointMenu.area_color = BLOCKPEN;
  109.   PointMenu.first_item = &PointItem[0];
  110.   if (!Init_PopUp_Menu(&PointMenu)) panic(POPUP_MENU);
  111. }
  112.  
  113.  
  114. Init_CurveMenu ()
  115.   CurveItem[0].next = &CurveItem[1];
  116.   CurveItem[1].next = &CurveItem[2];
  117.   CurveItem[2].next = &CurveItem[3];
  118.   CurveItem[3].next = &CurveItem[4]; 
  119.   CurveItem[4].next = &CurveItem[5]; 
  120.   CurveItem[5].next = &CurveItem[6]; 
  121.   CurveItem[6].next = &CurveItem[7]; 
  122.     
  123.   CurveMenu.depth = 2;
  124.   CurveMenu.width = 100;   /* minimum width */
  125.   CurveMenu.deactivate = SELECTUP;
  126.   CurveMenu.outline_color = OUTLINEPEN;
  127.   CurveMenu.area_color = BLOCKPEN;
  128.   CurveMenu.first_item = &CurveItem[0];
  129.   if (!Init_PopUp_Menu(&CurveMenu)) panic(POPUP_MENU);
  130.  
  131. }
  132.  
  133.  
  134. OpenLibraries ()
  135. {
  136.   /* Open the Intuition library -- connect to the routines in ROM 
  137.    * If the result is NULL then something went wrong so exit immediately
  138.    */
  139.   if (!(IntuitionBase = (struct IntuitionBase *) 
  140.            OpenLibrary("intuition.library",INTUITION_VERSION)))
  141.      panic(INTUITION);
  142.   else OpenBits |= INTUITION;
  143.   
  144.   /* Open the Graphics Library -- so that we can use the bit-map
  145.    * facilities of our window.
  146.    */
  147.  if (!(GfxBase = (struct GfxBase *)
  148.      OpenLibrary("graphics.library",GFX_VERSION)))
  149.      panic(GRAPHICS);
  150.   else OpenBits |= GRAPHICS;
  151.  
  152.  if (!(LayersBase = (struct LayersBase *)
  153.      OpenLibrary("layers.library",LAYERS_VERSION)))
  154.      panic(LAYERS);
  155.  else OpenBits |= LAYERS;
  156. }  
  157.  
  158.  
  159. /* SetupEnvironment : initializes the screen and window that 
  160.  * will be used. Assumes that all libraries have already been opened
  161.  */ 
  162. SetupEnvironment()
  163. { struct RastPort *RPort;
  164.  
  165.  if (!Init_MenuPackage()) panic(MENU_PACKAGE);
  166.  Init_PointMenu();
  167.  Init_CurveMenu();
  168.  
  169.   /* Open a customized Screen */
  170.   if (!(Screen = (struct Screen *)OpenScreen(&ScreenInfo)))
  171.      panic(SCREEN);
  172.   else OpenBits |= SCREEN;
  173.  
  174.   WindowInfo.Screen = Screen;
  175.   
  176.   /* Open A window in the new Window */
  177.   if (!(Window = (struct Window *)OpenWindow(&WindowInfo)))
  178.      panic(WINDOW);
  179.   else OpenBits |= WINDOW;
  180.  
  181.   /* set up window colors */
  182.   LoadRGB4(ViewPortAddress(Window),&ColorTable,COLORCOUNT);
  183.  
  184.   SetRast(Window->RPort,ERASE); /* wipe out everything -- no title bar */
  185. }
  186.  
  187.  
  188. /* panic: Prints out an error message about what went wrong during the
  189.  * setup/initialization phase of this program and ends the program
  190.  * gracefully by calling close_things before exiting with an error code
  191.  */
  192. panic(error_code)
  193. int error_code;
  194. {
  195.   switch (error_code) 
  196.    {
  197.      case LAYERS     :
  198.           fprintf(stderr,"splines: couldn't open layers library [%d]\n",
  199.                           LAYERS_VERSION);
  200.           break;
  201.      case POPUP_MENU :
  202.           fprintf(stderr,"splines: couldn't allocate popup menu\n");
  203.           break;
  204.      case MENU_PACKAGE :
  205.           fprintf(stderr,"splines: couldn't initialize menu package\n");
  206.           break;
  207.      case INTUITION : 
  208.           fprintf(stderr,"splines: couldn't find Intuition Library [%d]\n",
  209.                          INTUITION_VERSION);
  210.           break;
  211.      case GRAPHICS  : 
  212.           fprintf(stderr,"splines: couldn't find Graphics Library [%d]\n",
  213.                           GFX_VERSION);
  214.           break;
  215.      case SCREEN    :
  216.           fprintf(stderr,"splines: couldn't open Custom Screen.\n");
  217.           break;
  218.      case WINDOW    : 
  219.           fprintf(stderr,"splines: couldn't open Window.\n");
  220.           break;
  221.    }
  222.  
  223.   close_things();
  224.   exit(error_code);
  225. }
  226.  
  227.  
  228.  
  229.  
  230. /* close_things : closes the Libraries that have been opened and
  231.  * frees up whatever memory has been used.
  232.  */
  233. close_things()
  234. {
  235.   Dispose_PopUp(&PointMenu);
  236.   Dispose_PopUp(&CurveMenu);
  237.   Close_MenuPackage();
  238.   if (OpenBits & WINDOW)     CloseWindow(Window);
  239.   if (OpenBits & SCREEN)     CloseScreen(Screen);
  240.   if (OpenBits & LAYERS)     CloseLibrary(LayersBase);
  241.   if (OpenBits & GRAPHICS)   CloseLibrary(GfxBase);
  242.   if (OpenBits & INTUITION)  CloseLibrary(IntuitionBase);
  243. }
  244.  
  245.  
  246.